﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.SyntaxEditor.UI;

namespace Chaotic.Module.DBTool.Common
{
    public class SqlCompletionListPopup : CompletionListPopup
    { 
        MethodInfo? _methodInfo;

        public SqlCompletionListPopup(RadSyntaxEditor syntaxEditor) : base(syntaxEditor) 
        {
           
        }

        protected override void HandleSyntaxEditorKeyDown(object sender, PreviewSyntaxEditorKeyEventArgs e)
        {
            if (base.IsVisible && !e.OriginalArgs.Handled)
            {
                switch (e.Key)
                { 
                    case Key.Space: 
                        if(_methodInfo == null)
                        {
                            Type type = typeof(CompletionListPopup);
                            _methodInfo = type.GetMethod("HandleCompletionKey", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
                        }
                        _methodInfo?.Invoke(this, new object[] { e.OriginalArgs }); 
                        break;
                }
            }
            base.HandleSyntaxEditorKeyDown(sender, e);
        }
    }
}
